<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="author" content="zxh">
    <title>jQuery轮播图</title>
    <style>
        ul,
        li {
            margin: 0;
            padding: 0;
            list-style: none;
            cursor: pointer;
        }
        
        #box {
            width: 520px;
            height: 280px;
            margin: 100px auto;
            position: relative;
            border: 2px solid red;
        }
        
        #box .list li {
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }
        
        #box li.current {
            display: block;
        }
        
        #box .count {
            position: absolute;
            right: 10px;
            bottom: 10px;
        }
        
        #box .count li {
            float: left;
            width: 30px;
            height: 30px;
            margin-left: 10px;
            line-height: 30px;
            text-align: center;
            border-radius: 50%;
            background-color: #fa0;
            color: #fff;
            opacity: 0.8;
        }
        
        #box .count li.current {
            background-color: #f60;
            opacity: 1;
        }
    </style>
</head>

<body>
    <div id="box">
        <ul class="list">
            <li class="current"><img src="img/b1.jpg" alt=""></li>
            <li><img src="img/b2.jpg" alt=""></li>
            <li><img src="img/b3.jpg" alt=""></li>
            <li><img src="img/b4.jpg" alt=""></li>
            <li><img src="img/b5.jpg" alt=""></li>
        </ul>
        <ul class="count">
            <li>1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
        </ul>
    </div>
</body>

</html>
<script src="js/jquery.js"></script>
<script>
    // 记录当前显示图片的索引
    var current = 0
    // 保存定时器
    var timer = null
    timer = setInterval(autoMove, 1000)

    // 自动的
    function autoMove() {
        current++
        if (current >= $('.list li').length) {
            current = 0
        }
        $('.list li').eq(current).css('display', 'block').siblings().css('display', 'none')
        $('.count li').eq(current).addClass('current').siblings().removeClass('current')

    }
    // 手动的
    $('.count li').mouseover(function () {
        var index = current
        $('.list li').eq(current).css('display', 'block').siblings().css('display', 'none')
        $('.cuount li').eq(current).addClass('current').siblings().removeClass('current')
    })

    $('#box').mouseover(function(){
        clearInterval(timer)
    })
    $('#box').mouseout(function(){
        timer = setInterval(autoMove, 1000);
    })

</script>